package com.yc.videocache;

/**
 * Preconditions
 *
 * @since 2021-05-10
 */
public final class Preconditions {
    /**
     * checkNotNull
     *
     * @param reference
     * @param <T>
     * @return null
     * @throws NullPointerException
     */
    public static <T> T checkNotNull(T reference) {
        if (reference == null) {
            throw new NullPointerException();
        }
        return reference;
    }

    /**
     * checkAllNotNull
     *
     * @param references
     * @throws NullPointerException
     */
    public static void checkAllNotNull(Object... references) {
        for (Object reference : references) {
            if (reference == null) {
                throw new NullPointerException();
            }
        }
    }

    /**
     * checkNotNull
     *
     * @param reference
     * @param errorMessage
     * @param <T>
     * @return null
     * @throws NullPointerException
     */
    public static <T> T checkNotNull(T reference, String errorMessage) {
        if (reference == null) {
            throw new NullPointerException(errorMessage);
        }
        return reference;
    }

    static void checkArgument(boolean isExpression) {
        if (!isExpression) {
            throw new IllegalArgumentException();
        }
    }

    static void checkArgument(boolean isExpression, String errorMessage) {
        if (!isExpression) {
            throw new IllegalArgumentException(errorMessage);
        }
    }
}
